<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link
	href="${pageContext.request.contextPath }/admin/assets/css/bootstrap.min.css"
	rel="stylesheet" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/admin/css/style1.css" />
<link
	href="${pageContext.request.contextPath }/admin/assets/css/codemirror.css"
	rel="stylesheet">
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/admin/assets/css/ace.min.css" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/admin/assets/css/font-awesome.min.css" />
<link
	href="${pageContext.request.contextPath }/admin/Widget/icheck/icheck.css"
	rel="stylesheet" type="text/css" />
<link
	href="${pageContext.request.contextPath }/admin/layui-v2.4.5/layui/css/layui.css"
	rel="stylesheet" type="text/css" />
<title>添加配件</title>
</head>
<body>
	<div class="clearfix" id="add_picture">
		<div class="page_right_style">
			<div class="type_title">添加商品</div>
			<form action="${pageContext.request.contextPath }/saveStock"
				method="post" class="form form-horizontal" id="form-article-add"
				enctype="multipart/form-data">
				<input type="hidden" value="${model.stockId }" id="stockId"
					name="stockId">

				<div class="clea
				rfix cl">
					<label class="form-label col-2"><span class="c-red">*</span>配件名称：</label>
					<div class="formControls col-10">
						<input type="text" class="input-text" value="${model.stockName }"
							placeholder="" id="" name="stockName">
					</div>
				</div>
				<div class=" clearfix cl">

					<div class="Add_p_s">
						<label class="form-label col-2">进&nbsp;&nbsp;&nbsp;&nbsp;价：</label>
						<div class="formControls col-2">
							<input type="text" class="input-text"
								value="${model.stockMoney }" placeholder="" id=""
								name="stockMoney">
						</div>
					</div>
					<div class="Add_p_s">
						<label class="form-label col-2">售&nbsp;&nbsp;&nbsp;&nbsp;价：</label>
						<div class="formControls col-2">
							<input type="text" class="input-text"
								value="${model.stockPrice }" placeholder="" id=""
								name="stockPrice">
						</div>
					</div>
					<div class="Add_p_s">
						<label class="form-label col-2">品&nbsp;&nbsp;&nbsp;&nbsp;牌：</label>
						<div class="formControls col-2">
							<input type="text" class="input-text"
								value="${model.stockBrand }" placeholder="" id=""
								name="stockBrand">
						</div>
					</div>
					<div class="Add_p_s">
						<label class="form-label col-2">数&nbsp;&nbsp;&nbsp;&nbsp;量：</label>
						<div class="formControls col-2">
							<input type="text" class="input-text"
								value="${model.stockNumber }" placeholder="" id=""
								name="stockNumber">
						</div>
					</div>
					<div class="Add_p_s">
						<label class="form-label col-2">车&nbsp;&nbsp;&nbsp;&nbsp;型：</label>
						<div class="formControls col-2">
							<span class="select-box"> <select class="select"
								name="stockCarModel.cid" id="carModel">
									<option>请选择</option>
							</select>
							</span>
						</div>
					</div>

					<div class="Add_p_s">
						<label class="form-label col-2">型&nbsp;&nbsp;&nbsp;&nbsp;号：</label>
						<div class="formControls col-2">
							<span class="select-box"> <select class="select"
								name="stockModel.acmodelId" id="find_model">
									<option>请选择</option>
							</select>
							</span>
						</div>
					</div>



					<div class="Add_p_s">
						<div class="formControls col-2">
							<span class="select-box">
								<button type="button" class="layui-btn" id="test1">
									<i class="layui-icon">&#xe67c;</i>上传图片
								</button>
							</span>
						</div>
					</div>


				</div>

				<div class="clearfix cl">
					<label class="form-label col-2">作用：</label>
					<div class="formControls col-10">
						<input type="text" class="input-text"
							value="${model.stockEffect }" placeholder="" id=""
							name="stockEffect">
					</div>
				</div>

				<div class="clearfix cl">
					<div class="Button_operation">
						<button onClick="article_save_submit();"
							class="btn btn-primary radius" type="submit" id="addStock">
							<i class="icon-save "></i>保存
						</button>
						<button onClick="layer_close();" class="btn btn-default radius"
							type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
					</div>
				</div>
			</form>
		</div>
	</div>
	<script
		src="${pageContext.request.contextPath }/admin/js/jquery-1.9.1.min.js"></script>
	<script
		src="${pageContext.request.contextPath }/admin/assets/js/bootstrap.min.js"></script>
	<script
		src="${pageContext.request.contextPath }/admin/assets/js/typeahead-bs2.min.js"></script>
	<script
		src="${pageContext.request.contextPath }/admin/assets/layer/layer.js"
		type="text/javascript"></script>
	<script
		src="${pageContext.request.contextPath }/admin/assets/laydate/laydate.js"
		type="text/javascript"></script>
	<script type="text/javascript"
		src="${pageContext.request.contextPath }/admin/Widget/icheck/jquery.icheck.min.js"></script>
	<script src="${pageContext.request.contextPath }/admin/js/lrtk.js"
		type="text/javascript"></script>
	<script type="text/javascript"
		src="${pageContext.request.contextPath }/admin/js/H-ui.js"></script>
	<script type="text/javascript"
		src="${pageContext.request.contextPath }/admin/js/H-ui.admin.js"></script>
	<script type="text/javascript"
		src="${pageContext.request.contextPath }/admin/layui-v2.4.5/layui/layui.js"></script>
	<script type="text/javascript">

$(function(){
	selectCarModel();
	stockidJUD();
	layui.use(['form', 'element','upload'], function(){
		  var	from = layui.from;
		  var upload = layui.upload;
		  var element = layui.element;
		  //执行实例
		  var uploadInst = upload.render({
		    elem: '#test1' //绑定元素
		    ,url: '${pageContext.request.contextPath }/upload', //上传接口
		    exts:'jpg',//这里限定上传文件后缀为jpg
		    accept:'image/jpg',
		    field:'image',//对应的是后台的file类型的 image属性
		    bindActon:"#addStock",
		    done: function(res){
		      //上传完毕回调
		    }
		    ,error: function(){
		      //请求异常回调
		      alert('上传失败！！');
		    }
		  });
		});
})
//给下啦列表框赋值
var selectCarModel =function(){
	$	.ajax({
		url:"${pageContext.request.contextPath }/selectCarModel",
		dataType:'json',
		success:function(msg){
			
			var len_car = msg.carss.length;
			var len_model = msg.acmodelss.length;
			for (var i = 0; i < len_car; i++) {
				$("#carModel").append("<option value="+msg.carss[i].cid+">"+msg.carss[i].cname+"</option>")
			} 
			for (var i = 0; i < len_model; i++) {
				$("#find_model").append("<option value="+msg.acmodelss[i].acmodelId+">"+msg.acmodelss[i].acmodelName+"</option>")
			} 
			selectedOP();
		},error:function(){
			alert("失败！");
		}
	});
}

//动态选中
var selectedOP = function() {
	$('#carModel option').each(function() {
		if ($(this).val() == "${model.stockCarModel.cid }" ) {
			$(this).attr('selected', true);
		}
	});
	$('#find_model option').each(function() {
		if ($(this).val() == "${model.stockModel.acmodelId }" ) {
			$(this).attr('selected', true);
		}
	});
};
//判断是添加还是修改
var stockidJUD = function(){
	if($("#stockId").val()==null || $("#stockId").val()==""){
		$("form").attr("action","${pageContext.request.contextPath }/saveStock");
	}else{
		$("form").attr("action","${pageContext.request.contextPath }/updateStock");	
		
	};
}

$(function() { 
	$("#add_picture").fix({
		float:'right',
		skin : 'green',	
		durationTime :false,
		stylewidth:'220',
		spacingw:0,
		spacingh:260,
	});
});
$( document).ready(function(){
	//初始化宽度、高度
	   $(".widget-box").height($(window).height()); 
	   $(".page_right_style").height($(window).height()); 
	   $(".page_right_style").width($(window).width()); 
	  //当文档窗口发生改变时 触发  
	    $(window).resize(function(){

		 $(".widget-box").height($(window).height()); 
		 $(".page_right_style").height($(window).height()); 
		 $(".page_right_style").width($(window).width()); 
		});	
	});
$(function(){
	var ue = UE.getEditor('editor');
});
		
var code;
		
function showCode(str) {
	if (!code) code = $("#code");
	code.empty();
	code.append("<li>"+str+"</li>");
}
</script>
	<script type="text/javascript">
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$list = $("#fileList"),
	$btn = $("#btn-star"),
	state = "pending",
	uploader;

})( jQuery );
</script>
</body>
</html>